package org.wanxian.stores.util;

import android.content.Context;
import android.graphics.Bitmap;
import android.graphics.BitmapFactory;
import android.graphics.drawable.BitmapDrawable;

import java.io.InputStream;

/**
 * Created by misakayaho on 2016/4/3.
 */
public class ImageResourceUtil {

	/**
	 * 
	 * @param context
	 * @param resId
	 * @return
	 */
    public static BitmapDrawable readBitmapDrawable(Context context, int resId){
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.RGB_565;
        options.inPurgeable = true;
        options.inInputShareable = true;
        InputStream is = context.getResources().openRawResource(resId);

        return new BitmapDrawable(context.getResources(), BitmapFactory.decodeStream(is,null,options));
    }

    /**
     * 
     * @param context
     * @param resId
     * @return
     */
    public static Bitmap readBitmap(Context context, int resId){
        BitmapFactory.Options options = new BitmapFactory.Options();
        options.inPreferredConfig = Bitmap.Config.RGB_565;
        options.inPurgeable = true;
        options.inInputShareable = true;
        options.inSampleSize = 2;
        InputStream is = context.getResources().openRawResource(resId);
        return BitmapFactory.decodeStream(is,null,options);
    }
}